package com.example.easypoi.service.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.easypoi.entity.DigitalElasticElement;
import com.example.easypoi.entity.DigitalPressureGauge;
import com.example.easypoi.entity.ExcelUser;
import com.example.easypoi.mapper.DigitalElasticElementMapper;
import com.example.easypoi.mapper.DigitalPressureGaugeMapper;
import com.example.easypoi.service.ExcelImportService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ExcelImportServiceImpl implements ExcelImportService {


    /**
     * excel 2003 suffix
     */
    private static final String EXCEL_XLS_SUFFIX = ".xls" ;

    /**
     * excel 2007 或以上 suffix
     */
    private static final String EXCEL_XLSX_SUFFIX = ".xlsx";

    /**
     * 分隔符 "."
     */
    public static final String POINT = ".";

    @Autowired
    private DigitalPressureGaugeMapper digitalPressureGaugeMapper;
    @Autowired
    private DigitalElasticElementMapper digitalElasticElementMapper;

    public  List<List<Object>> importFile (MultipartFile multipartFile) {
        if(multipartFile == null) {
            return null ;
        }
        if(multipartFile.getOriginalFilename().endsWith(EXCEL_XLS_SUFFIX)) {
            try {
                return readXls(multipartFile.getInputStream());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        if(multipartFile.getOriginalFilename().endsWith(EXCEL_XLSX_SUFFIX)) {
            try {
                return readXlsx(multipartFile.getInputStream());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        throw new RuntimeException("文件不对,必须是excel文件，后缀名以："+EXCEL_XLS_SUFFIX + " 或者 "+ EXCEL_XLSX_SUFFIX);
    }


    public List<List<Object>> readXls(InputStream inputStream) {
        List<List<Object>> list = new ArrayList<>();
        // 读取excel
        HSSFWorkbook workbook = null;
        try {
            workbook = new HSSFWorkbook(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 获取sheet 页数量
        int sheets = workbook.getNumberOfSheets();
        for(int num = 0 ; num < sheets ; num++ ) {
            HSSFSheet sheet = workbook.getSheetAt(num);
            if(null == sheet) {
                continue ;
            }
            // sheet 页的总行数
            int rows = sheet.getLastRowNum();
            // startRow 开始读取的行数 --- 第二行开始读
            for( int startRow = 1 ;startRow <= rows  ; startRow ++) {
                HSSFRow row = sheet.getRow(startRow);
                List<Object> rowList = new ArrayList<>();
                if(null != row) {
                    // row 行中的 单元格总个数
                    short cells = row.getLastCellNum();
                    for(int x = 0 ; x <= cells ; x++) {
                        HSSFCell cell = row.getCell(x);
                        if(null == cell) {
                            rowList.add("");
                        }else {
                            rowList.add(getXlsValue(cell));
                        }
                    }
                    list.add(rowList);
                }
            }
        }
        return list;
    }

    /**
     * description: 获取 03 版 excel数据
     * @param cell
     * @return String
     * @version v1.0
     * @author yangjun
     * @date
     */
    public String getXlsValue(HSSFCell cell) {
        if ( cell.getCellType() == cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == cell.CELL_TYPE_NUMERIC) {
            String cellValue = "";
            if(HSSFDateUtil.isCellDateFormatted(cell)){
                Date date = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
                cellValue = new SimpleDateFormat("yyyy/MM/dd").format(date);
            }else{
                DecimalFormat df = new DecimalFormat("#.##");
                cellValue = df.format(cell.getNumericCellValue());
                String strArr = cellValue.substring(cellValue.lastIndexOf(POINT)+1,cellValue.length());
                if(strArr.equals("00")){
                    cellValue = cellValue.substring(0, cellValue.lastIndexOf(POINT));
                }
            }
            return cellValue;
        } else {
            // 其他类型的值，统一设置为 string
            // http://blog.csdn.net/ysughw/article/details/9288307
            cell.setCellType(Cell.CELL_TYPE_STRING);
            return String.valueOf(cell.getStringCellValue());
        }
    }

    /**
     * description: 读取07或以上版本的 excel
     * @param
     * @throws Exception
     * @return List<List<Object>>
     * @version v1.0
     * @author yangjun
     * @date
     */
    private List<List<Object>> readXlsx(InputStream inputStream) throws Exception {
        List<List<Object>> list = new ArrayList<>();
        // 读取excel ，封装到 XSSFWorkbook 对象
        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
        int sheets = workbook.getNumberOfSheets();
        for(int num = 0 ;num < sheets ; num++) {
            XSSFSheet sheet = workbook.getSheetAt(num);
            if(null == sheet) {
                continue ;
            }
            // 获取sheet页的总行数
            int rows = sheet.getLastRowNum();
            for(int startRow = 1 ; startRow <= rows ; startRow++ ) {
                // startRow 开始读取的行数， 从第二行开始读取
                XSSFRow row = sheet.getRow(startRow);
                List<Object> rowList = new ArrayList<>();
                if(null != row) {
                    // 获取行总单元格个数
                    short cells = row.getLastCellNum();
                    for(int x = 0 ; x < cells ; x++) {
                        XSSFCell cell = row.getCell(x);
                        if(cell == null) {
                            rowList.add("");
                        }else {
                            rowList.add(getXlsxValue(cell));
                        }
                    }
                    list.add(rowList);
                }
            }
        }
        return list;
    }

    /**
     * description: 获取07或以上版本 excel 数据
     * @param cell
     * @return Object
     * @version v1.0
     * @author yangjun
     * @date
     */
    private  Object getXlsxValue(XSSFCell cell) {
        if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            String cellValue = "";
            if (DateUtil.isCellDateFormatted(cell)) {
                Date date = DateUtil.getJavaDate(cell.getNumericCellValue());
                cellValue = new SimpleDateFormat("yyyy/MM/dd").format(date);
            } else {
                DecimalFormat df = new DecimalFormat("#.##");
                cellValue = df.format(cell.getNumericCellValue());
                String strArr = cellValue.substring(cellValue.lastIndexOf(POINT) + 1, cellValue.length());
                if (strArr.equals("00")) {
                    cellValue = cellValue.substring(0, cellValue.lastIndexOf(POINT));
                }
            }
            return cellValue;
        } else {
            // 其他类型的值，统一设置为 string
            // http://blog.csdn.net/ysughw/article/details/9288307
            //cell.setCellType(Cell.CELL_TYPE_STRING);
            return String.valueOf(cell.getStringCellValue());
        }
    }


    public String templateDerive(DigitalPressureGauge digitalPressureGauge) {
        StringBuilder sb = new StringBuilder();
//        return list;
        //这里是模板的路径
        TemplateExportParams params = new TemplateExportParams(
                "excel/数字压力计校准记录导出模板.xlsx");
        Map<String, Object> map = new HashMap<>();
        List<ExcelUser> list = new ArrayList<>();
        //设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
        map.put("1001", digitalPressureGauge.getData1001());
        map.put("1002", digitalPressureGauge.getData1002());
        map.put("1003", digitalPressureGauge.getData1003());
        map.put("1004", digitalPressureGauge.getData1004());
        map.put("1005", digitalPressureGauge.getData1005());
        map.put("1006", digitalPressureGauge.getData1006());
        map.put("1007", digitalPressureGauge.getData1007());
        map.put("1008", digitalPressureGauge.getData1008());
        map.put("1009", digitalPressureGauge.getData1009());
        map.put("1010", digitalPressureGauge.getData1010());
        map.put("1011", digitalPressureGauge.getData1011());
        map.put("1012", digitalPressureGauge.getData1012());
        map.put("1013", digitalPressureGauge.getData1013());
        map.put("1014", digitalPressureGauge.getData1014());
        map.put("1015", digitalPressureGauge.getData1015());
        map.put("1016", digitalPressureGauge.getData1016());
        map.put("1017", digitalPressureGauge.getData1017());
        map.put("1018", digitalPressureGauge.getData1018());
        map.put("1019", digitalPressureGauge.getData1019());
        map.put("1020", digitalPressureGauge.getData1020());
        map.put("1021", digitalPressureGauge.getData1021());
        map.put("1022", digitalPressureGauge.getData1022());
        map.put("1023", digitalPressureGauge.getData1023());
        map.put("1029", digitalPressureGauge.getData1029());
        map.put("1024", digitalPressureGauge.getData1024());
        map.put("1025", digitalPressureGauge.getData1025());
        map.put("1026", digitalPressureGauge.getData1026());
        map.put("1027", digitalPressureGauge.getData1027());
        map.put("1028", digitalPressureGauge.getData1028());
        map.put("1030", digitalPressureGauge.getData1030());
        map.put("1031", digitalPressureGauge.getData1031());
        map.put("1032", digitalPressureGauge.getData1032());
        map.put("1033", digitalPressureGauge.getData1033());
        map.put("1034", digitalPressureGauge.getData1034());
        map.put("1035", digitalPressureGauge.getData1035());
        map.put("1036", digitalPressureGauge.getData1036());
        map.put("1037", digitalPressureGauge.getData1037());
        map.put("1038", digitalPressureGauge.getData1038());
        map.put("1039", digitalPressureGauge.getData1039());
        map.put("1040", digitalPressureGauge.getData1040());
        map.put("1041", digitalPressureGauge.getData1041());
        map.put("1042", digitalPressureGauge.getData1042());
        map.put("1043", digitalPressureGauge.getData1043());
        map.put("1044", digitalPressureGauge.getData1044());
        map.put("1045", digitalPressureGauge.getData1045());
        map.put("1046", digitalPressureGauge.getData1046());
        map.put("1047", digitalPressureGauge.getData1047());
        map.put("1048", digitalPressureGauge.getData1048());
        map.put("1049", digitalPressureGauge.getData1049());
        map.put("1050", digitalPressureGauge.getData1050());
        map.put("1051", digitalPressureGauge.getData1051());
        map.put("1052", digitalPressureGauge.getData1052());
        map.put("1053", digitalPressureGauge.getData1053());
        map.put("1054", digitalPressureGauge.getData1054());
        map.put("1055", digitalPressureGauge.getData1055());
        map.put("1056", digitalPressureGauge.getData1056());
        map.put("1057", digitalPressureGauge.getData1057());
        map.put("1058", digitalPressureGauge.getData1058());
        map.put("1059", digitalPressureGauge.getData1059());
        map.put("1060", digitalPressureGauge.getData1060());
        map.put("1061", digitalPressureGauge.getData1061());
        map.put("1062", digitalPressureGauge.getData1062());
        map.put("1063", digitalPressureGauge.getData1063());
        map.put("1064", digitalPressureGauge.getData1064());
        map.put("1065", digitalPressureGauge.getData1065());
        map.put("1066", digitalPressureGauge.getData1066());
        map.put("1067", digitalPressureGauge.getData1067());
        map.put("1068", digitalPressureGauge.getData1068());
        map.put("1069", digitalPressureGauge.getData1069());
        map.put("1070", digitalPressureGauge.getData1070());
        map.put("1071", digitalPressureGauge.getData1071());
        map.put("1072", digitalPressureGauge.getData1072());
        map.put("1073", digitalPressureGauge.getData1073());
        map.put("1074", digitalPressureGauge.getData1074());
        map.put("1075", digitalPressureGauge.getData1075());
        map.put("1076", digitalPressureGauge.getData1076());
        map.put("1077", digitalPressureGauge.getData1077());
        map.put("1078", digitalPressureGauge.getData1078());
        map.put("1079", digitalPressureGauge.getData1079());
        map.put("1080", digitalPressureGauge.getData1080());

        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        //存储位置
        File savefile = new File("D:/excel/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:/excel/" +digitalPressureGauge.getData1001() + "模板导出.xlsx");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        try {
            workbook.write(fos);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            fos.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return "成功";

    }


    @Override
    public IPage<DigitalPressureGauge> getAllDigitalPressureGauge(DigitalPressureGauge digitalPressureGauge, Integer pageNumber, Integer pageSize) {

        QueryWrapper<DigitalPressureGauge> wrapper=new QueryWrapper<>();
        //wrapper.eq(digitalPressureGauge.getData1001() != null,"Data1001",digitalPressureGauge.getData1001());

        if(digitalPressureGauge.getSelectStartTime() != null && digitalPressureGauge.getSelectEndTime() != null){

            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//根据自己情况
            String selectStartTime=sdf.format(digitalPressureGauge.getSelectStartTime());  //Date转String
            String selectEndtTime=sdf.format(digitalPressureGauge.getSelectEndTime());  //Date转String
            wrapper.between("start_time",selectStartTime,selectEndtTime);

        }
        wrapper.like(digitalPressureGauge.getData1004() != null && digitalPressureGauge.getData1004() != "","Data1004",digitalPressureGauge.getData1004());

        wrapper.orderByDesc("start_time");
        IPage<DigitalPressureGauge> ipage = digitalPressureGaugeMapper.selectPage(new Page<>(pageNumber,pageSize),wrapper);
        return ipage;
    }

    @Override
    public List<DigitalPressureGauge> getAllData1004() {
//        QueryWrapper<DigitalPressureGauge> wapper = new QueryWrapper<>();
//        wapper.select("Data1001");
        return digitalPressureGaugeMapper.getAllData1004();
    }

    @Override
    public IPage<DigitalElasticElement> getAllDigitalElasticElement(DigitalElasticElement digitalElasticElement, Integer pageNumber, Integer pageSize) {

        QueryWrapper<DigitalElasticElement> wrapper=new QueryWrapper<>();

        if(digitalElasticElement.getSelectStartTime() != null && digitalElasticElement.getSelectEndTime() != null){

            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//根据自己情况
            String selectStartTime=sdf.format(digitalElasticElement.getSelectStartTime());  //Date转String
            String selectEndtTime=sdf.format(digitalElasticElement.getSelectEndTime());  //Date转String
            wrapper.between("start_time",selectStartTime,selectEndtTime);

            //SimpleDateFormat sdf = new SimpleDateFormat();
        }
        wrapper.like(digitalElasticElement.getData1005() != null && digitalElasticElement.getData1005() != "","Data1005",digitalElasticElement.getData1005());

        wrapper.orderByDesc("start_time");
        IPage<DigitalElasticElement> ipage = digitalElasticElementMapper.selectPage(new Page<>(pageNumber,pageSize),wrapper);
        return ipage;
    }

    @Override
    public List<DigitalElasticElement> getAllData1005() {
//        QueryWrapper<DigitalElasticElement> wapper = new QueryWrapper<>();
//        wapper.select("Data1005");
        return digitalElasticElementMapper.getAllData1005();
    }

    @Override
    public String exportElastic(DigitalElasticElement digitalElasticElement1) {
        StringBuilder sb = new StringBuilder();
//        return list;
        //这里是模板的路径
        TemplateExportParams params = new TemplateExportParams(
                "excel/弹性元件式一般指针表校准记录导出模板.xlsx");
        Map<String, Object> map = new HashMap<>();
        List<ExcelUser> list = new ArrayList<>();
        //设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
        map.put("1001", digitalElasticElement1.getData1001());
        map.put("1002", digitalElasticElement1.getData1002());
        map.put("1003", digitalElasticElement1.getData1003());
        map.put("1004", digitalElasticElement1.getData1004());
        map.put("1005", digitalElasticElement1.getData1005());
        map.put("1006", digitalElasticElement1.getData1006());
        map.put("1007", digitalElasticElement1.getData1007());
        map.put("1008", digitalElasticElement1.getData1008());
        map.put("1009", digitalElasticElement1.getData1009());
        map.put("1010", digitalElasticElement1.getData1010());
        map.put("1011", digitalElasticElement1.getData1011());
        map.put("1012", digitalElasticElement1.getData1012());
        map.put("1013", digitalElasticElement1.getData1013());
        map.put("1014", digitalElasticElement1.getData1014());
        map.put("1015", digitalElasticElement1.getData1015());
        map.put("1016", digitalElasticElement1.getData1016());
        map.put("1017", digitalElasticElement1.getData1017());
        map.put("1018", digitalElasticElement1.getData1018());
        map.put("1019", digitalElasticElement1.getData1019());
        map.put("1020", digitalElasticElement1.getData1020());
        map.put("1021", digitalElasticElement1.getData1021());
        map.put("1022", digitalElasticElement1.getData1022());
        map.put("1023", digitalElasticElement1.getData1023());
        map.put("1029", digitalElasticElement1.getData1029());
        map.put("1024", digitalElasticElement1.getData1024());
        map.put("1025", digitalElasticElement1.getData1025());
        map.put("1026", digitalElasticElement1.getData1026());
        map.put("1027", digitalElasticElement1.getData1027());
        map.put("1028", digitalElasticElement1.getData1028());
        map.put("1030", digitalElasticElement1.getData1030());
        map.put("1031", digitalElasticElement1.getData1031());
        map.put("1032", digitalElasticElement1.getData1032());
        map.put("1033", digitalElasticElement1.getData1033());
        map.put("1034", digitalElasticElement1.getData1034());
        map.put("1035", digitalElasticElement1.getData1035());
        map.put("1036", digitalElasticElement1.getData1036());
        map.put("1037", digitalElasticElement1.getData1037());
        map.put("1038", digitalElasticElement1.getData1038());
        map.put("1039", digitalElasticElement1.getData1039());
        map.put("1040", digitalElasticElement1.getData1040());
        map.put("1041", digitalElasticElement1.getData1041());
        map.put("1042", digitalElasticElement1.getData1042());
        map.put("1043", digitalElasticElement1.getData1043());
        map.put("1044", digitalElasticElement1.getData1044());
        map.put("1045", digitalElasticElement1.getData1045());
        map.put("1046", digitalElasticElement1.getData1046());
        map.put("1047", digitalElasticElement1.getData1047());
        map.put("1048", digitalElasticElement1.getData1048());
        map.put("1049", digitalElasticElement1.getData1049());
        map.put("1050", digitalElasticElement1.getData1050());
        map.put("1051", digitalElasticElement1.getData1051());
        map.put("1052", digitalElasticElement1.getData1052());
        map.put("1053", digitalElasticElement1.getData1053());
        map.put("1054", digitalElasticElement1.getData1054());
        map.put("1055", digitalElasticElement1.getData1055());
        map.put("1056", digitalElasticElement1.getData1056());
        map.put("1057", digitalElasticElement1.getData1057());
        map.put("1058", digitalElasticElement1.getData1058());
        map.put("1059", digitalElasticElement1.getData1059());
        map.put("1060", digitalElasticElement1.getData1060());
        map.put("1061", digitalElasticElement1.getData1061());
        map.put("1062", digitalElasticElement1.getData1062());
        map.put("1063", digitalElasticElement1.getData1063());
        map.put("1064", digitalElasticElement1.getData1064());
        map.put("1065", digitalElasticElement1.getData1065());
        map.put("1066", digitalElasticElement1.getData1066());
        map.put("1067", digitalElasticElement1.getData1067());
        map.put("1068", digitalElasticElement1.getData1068());
        map.put("1069", digitalElasticElement1.getData1069());
        map.put("1070", digitalElasticElement1.getData1070());
        map.put("1071", digitalElasticElement1.getData1071());
        map.put("1072", digitalElasticElement1.getData1072());
        map.put("1073", digitalElasticElement1.getData1073());
        map.put("1074", digitalElasticElement1.getData1074());
        map.put("1075", digitalElasticElement1.getData1075());
        map.put("1076", digitalElasticElement1.getData1076());
        map.put("1077", digitalElasticElement1.getData1077());
        map.put("1078", digitalElasticElement1.getData1078());
        map.put("1079", digitalElasticElement1.getData1079());
        map.put("1080", digitalElasticElement1.getData1080());
        map.put("1081", digitalElasticElement1.getData1081());
        map.put("1082", digitalElasticElement1.getData1082());
        map.put("1083", digitalElasticElement1.getData1083());
        map.put("1084", digitalElasticElement1.getData1084());
        map.put("1085", digitalElasticElement1.getData1085());
        map.put("1086", digitalElasticElement1.getData1086());
        map.put("1087", digitalElasticElement1.getData1087());
        map.put("1088", digitalElasticElement1.getData1088());
        map.put("1089", digitalElasticElement1.getData1089());
        map.put("1090", digitalElasticElement1.getData1090());
        map.put("1091", digitalElasticElement1.getData1091());
        map.put("1092", digitalElasticElement1.getData1092());
        map.put("1093", digitalElasticElement1.getData1093());
        map.put("1094", digitalElasticElement1.getData1094());
        map.put("1095", digitalElasticElement1.getData1095());
        map.put("1096", digitalElasticElement1.getData1096());
        map.put("1097", digitalElasticElement1.getData1097());
        map.put("1098", digitalElasticElement1.getData1098());
        map.put("1099", digitalElasticElement1.getData1099());
        map.put("1100", digitalElasticElement1.getData1100());
        map.put("1101", digitalElasticElement1.getData1101());
        map.put("1102", digitalElasticElement1.getData1102());
        map.put("1103", digitalElasticElement1.getData1103());
        map.put("1104", digitalElasticElement1.getData1104());
        map.put("1105", digitalElasticElement1.getData1105());
        map.put("1106", digitalElasticElement1.getData1106());
        map.put("1107", digitalElasticElement1.getData1107());
        map.put("1108", digitalElasticElement1.getData1108());
        map.put("1109", digitalElasticElement1.getData1109());
        map.put("1110", digitalElasticElement1.getData1110());
        map.put("1111", digitalElasticElement1.getData1111());
        map.put("1112", digitalElasticElement1.getData1112());
        map.put("1113", digitalElasticElement1.getData1113());
        map.put("1114", digitalElasticElement1.getData1114());
        map.put("1115", digitalElasticElement1.getData1115());
        map.put("1116", digitalElasticElement1.getData1116());
        map.put("1117", digitalElasticElement1.getData1117());
        map.put("1118", digitalElasticElement1.getData1118());
        map.put("1119", digitalElasticElement1.getData1119());
        map.put("1120", digitalElasticElement1.getData1120());
        map.put("1121", digitalElasticElement1.getData1121());
        map.put("1122", digitalElasticElement1.getData1122());
        map.put("1123", digitalElasticElement1.getData1123());
        map.put("1124", digitalElasticElement1.getData1124());
        map.put("1125", digitalElasticElement1.getData1125());
        map.put("1126", digitalElasticElement1.getData1126());
        map.put("1127", digitalElasticElement1.getData1127());
        map.put("1128", digitalElasticElement1.getData1128());
        map.put("1129", digitalElasticElement1.getData1129());
        map.put("1130", digitalElasticElement1.getData1130());
        map.put("1131", digitalElasticElement1.getData1131());
        map.put("1132", digitalElasticElement1.getData1132());
        map.put("1133", digitalElasticElement1.getData1133());
        map.put("1134", digitalElasticElement1.getData1134());
        map.put("1135", digitalElasticElement1.getData1135());
        map.put("1136", digitalElasticElement1.getData1136());
        map.put("1137", digitalElasticElement1.getData1137());
        map.put("1138", digitalElasticElement1.getData1138());
        map.put("1139", digitalElasticElement1.getData1139());
        map.put("1140", digitalElasticElement1.getData1140());
        map.put("1141", digitalElasticElement1.getData1141());
        map.put("1142", digitalElasticElement1.getData1142());
        map.put("1143", digitalElasticElement1.getData1143());
        map.put("1144", digitalElasticElement1.getData1144());
        map.put("1145", digitalElasticElement1.getData1145());
        map.put("1146", digitalElasticElement1.getData1146());
        map.put("1147", digitalElasticElement1.getData1147());
        map.put("1148", digitalElasticElement1.getData1148());
        map.put("1149", digitalElasticElement1.getData1149());
        map.put("1150", digitalElasticElement1.getData1150());
        map.put("1151", digitalElasticElement1.getData1151());
        map.put("1152", digitalElasticElement1.getData1152());
        map.put("1153", digitalElasticElement1.getData1153());
        map.put("1154", digitalElasticElement1.getData1154());
        map.put("1155", digitalElasticElement1.getData1155());
        map.put("1156", digitalElasticElement1.getData1156());
        map.put("1157", digitalElasticElement1.getData1157());
        map.put("1158", digitalElasticElement1.getData1158());
        map.put("1159", digitalElasticElement1.getData1159());
        map.put("1160", digitalElasticElement1.getData1160());
        map.put("1161", digitalElasticElement1.getData1161());
        map.put("1162", digitalElasticElement1.getData1162());
        map.put("1163", digitalElasticElement1.getData1163());

        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        //存储位置
        File savefile = new File("D:/excel/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:/excel/" +digitalElasticElement1.getData1001() + "弹性原件式.xlsx");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        try {
            workbook.write(fos);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            fos.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return "成功";
    }
}
